//
//  APPLETextField.swift
//  123
//
//  Created by pangjiaxing on 15/12/27.
//  Copyright © 2015年 pangjiaxing. All rights reserved.
//

import UIKit

class APPLETextField: UIView {
    
    @IBAction func didClickCancelButton() {
        
        textfield.resignFirstResponder()
        
        leftLayout.constant=0
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.textfield.layoutIfNeeded()
        }
        
        
    }
    @IBAction func editingBegin(sender: AnyObject) {
        leftLayout.constant=60
        UIView.animateWithDuration(0.25) { () -> Void in
            self.textfield.layoutIfNeeded()
        }
    }
    
    @IBOutlet weak var leftLayout: NSLayoutConstraint!
    @IBOutlet weak var textfield: UITextField!
    
    class func searchView() -> APPLETextField {
    
        return NSBundle.mainBundle().loadNibNamed("APPLETextField", owner: nil, options: nil ).last!as!APPLETextField
    }
    
    override func awakeFromNib() {
        
       
    // 设置左边视图
    let leftView = UIImageView()
    leftView.image = UIImage(named: "searchbar_textfield_search_icon")
    // 指定大小
    leftView.frame.size = CGSizeMake(frame.height, frame.height)
    // contentMode
    // conter 是代表居中，以原样大小显示
    leftView.contentMode = .Center
    textfield.leftView = leftView
    textfield.leftViewMode = .Always
    }
    
}
